package de.tum.softwarengineering1.ws201112.team11.sudoku.util;

import java.util.Random;

import de.tum.softwarengineering1.ws201112.team11.sudoku.logic.BruteForceSolver;
import de.tum.softwarengineering1.ws201112.team11.sudoku.model.SudokuBoard;

public class BoardUtil {
	
public static void remainingValues(SudokuBoard board, int number) {
		
		int[][] matrix = board.getValues();
		Random rand = new Random();
		int pos, elements, no, xi, yi;

		for (int i = 1; i <= 9; i++) {
		    no = rand.nextInt(80) + 1;
		    xi = no % 9;
		    yi = no / 9;
		    if (matrix[xi][yi] == 0)
			matrix[xi][yi] = i;
		    else
			i--;
		}
		board.setValues(matrix);
		board.setSolver(new BruteForceSolver());
		board.solve();
		
		//
		no = rand.nextInt(number) + 20;
		elements = 81 - no;
		matrix = board.getValues();
		for (int i = 0; i < elements; i++) {
		    pos = rand.nextInt(80) + 1;
		    xi = pos % 9;
		    yi = pos / 9;
		    if (matrix[xi][yi] != 0)
			matrix[xi][yi] = 0;
		    else
			i--;
		}
		board.setValues(matrix);
	    }

}
